package com.liuyi.netty.im.lychat.modular.service;

import com.liuyi.netty.im.lychat.modular.caches.GroupMemberCache;
import com.liuyi.netty.im.lychat.modular.entity.GroupMember;
import com.liuyi.netty.im.lychat.modular.mapper.GroupMemberMapper;
import com.liuyi.rapid.develop.mybatis.plus.base.IBaseService;

import java.util.List;

/**
 * <p>
 * 群组成员表 服务类
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-12-29
 */
public interface IGroupMemberService extends IBaseService<GroupMember> {

    @Override
    default Class<GroupMember> getEntityClass() {
        return GroupMember.class;
    }

    @Override
    @SuppressWarnings("unchecked")
    default GroupMemberMapper getMapper() {
        return (GroupMemberMapper) getBaseMapper();
    }

    GroupMemberCache cache();

    /**
     * 检查群成员
     *
     * @param userId  用户id
     * @param groupId 组id
     * @return boolean
     */
    default boolean checkGroupMember(String userId, String groupId) {
        return count(q().eq(GroupMember.USER_ID, userId).eq(GroupMember.GROUP_NO, groupId)) > 0;
    }

    /**
     * 解散群
     *
     * @param groupId 组id
     */
    void dissolveGroup(String groupId);

    /**
     * 创建组
     *
     * @param groupId 组id
     * @param userId  用户id
     */
    GroupMember createGroup(String groupId, String userId);

    /**
     * 创建组
     *
     * @param groupId   组id
     * @param userId    用户id
     * @param memberIds 成员
     */
    GroupMember createGroup(String groupId, String userId, List<String> memberIds);

    /**
     * 添加成员
     * <pre>
     *     需要合理刷新群成员缓存
     * </pre>
     *
     * @param groupId 组id
     * @param userIds  用户id
     */
    void addMember(String groupId, List<String> userIds);

    void wrapper(GroupMember member);

    Object groupProfile(String userId, String groupId);
}
